﻿-- =============================================
-- Author:		Naresh N Jamadagni
-- Create date: 21 May 2012
-- Description:	Delets the registered computers 
-- =============================================
CREATE PROCEDURE [DeleteComputer]
(
	@ComputerName nvarchar(100) 
)
AS

BEGIN
   SET NOCOUNT ON;
   DECLARE @ComputerId Int;
   SET @ComputerId = -1;
   SELECT @ComputerId = Id from dbo.Computer where ComputerName = @ComputerName;
   IF @ComputerId = -1 
	BEGIN
		RAISERROR('%s Computer does not exist',10,1,@ComputerName);
	END
   ELSE
	BEGIN
		DELETE FROM [dbo].CPUUSAGE WHERE ComputerId = @ComputerId;
		DELETE FROM [dbo].RAMUSAGE WHERE ComputerId = @ComputerId;
		DELETE FROM [dbo].DNSSERVER WHERE ComputerId = @ComputerId;
		DELETE FROM [dbo].WINSSERVER WHERE ComputerId = @ComputerId;
		DELETE FROM [dbo].NETWORKINTERFACE WHERE ComputerId = @ComputerId;
		DELETE FROM [dbo].PROCESS WHERE ComputerId = @ComputerId;
		DELETE FROM [dbo].DEPENDENTSERVICE WHERE ComputerId = @ComputerId;
		DELETE FROM [dbo].SERVICE WHERE ComputerId = @ComputerId;
		DELETE FROM [dbo].Drive WHERE ComputerId = @ComputerId;
		DELETE FROM [dbo].EventLog WHERE ComputerId = @ComputerId;
		DELETE FROM [dbo].Computer where ComputerName = @ComputerName;
	END
END

